home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / f1 / hpn.arj / PUZZLE.BAS < prev    next >
Encoding:
BASIC Source File  |  1992-06-14  |  5.8 KB  |  175 lines

  1. DECLARE SUB datos ()
  2. DECLARE SUB entrada (f, p)
  3. DECLARE SUB figuras ()
  4. DECLARE SUB inicio ()
  5. DECLARE SUB juego ()
  6. DECLARE SUB solucion ()
  7. DECLARE SUB pantalla ()
  8. DECLARE SUB pantalla2 ()
  9. DECLARE SUB mueve (f, p)
  10. DECLARE SUB dibuja (i, c)
  11. DIM SHARED num(10) AS STRING, a(4) AS STRING, f(10) AS INTEGER, t(10) AS INTEGER, tb(6, 5) AS INTEGER, dimx(4) AS INTEGER, dimy(4) AS INTEGER, posx(10) AS INTEGER, posy(10) AS INTEGER, cs AS STRING * 4, sol(4) AS STRING, mov AS INTEGER
  12. DATA 1,1,0,0,0,1,1,0
  13. DATA 4,1,1,4,3,1,2,5,1,1,1,2,3,3,2,2,5,2,2,5,3,4,1,4,4,3,4,2,5,4
  14. DATA u2e2r2f2d7g2l2h2u8
  15. DATA e4d12nr4nl4
  16. DATA u2e2r4f2d2g8r8
  17. DATA u2e2r4f2d2g2nl2f2d2g2l4h2
  18. DATA ne6d4r4nu4nr4d6nr2l2
  19. DATA u4nr8d6r6f2d2g2l6
  20. DATA d2r6f2d2g2l4h2u8e2r4f2
  21. DATA bu4r8d2g4nr2nl2g2d4
  22. DATA f2r4f2d2g2l4h2u2e2h2u2e2r4f2d2g2
  23. DATA bf2br4l6h2u2e2r4f2d8g2l4h2
  24. REM  **- Solución -**
  25. DATA "74019352643223646134342263633133515174720404223233530101717124943232626253030213"
  26. DATA "13412424646431345252030173731204047174515133326363127274546161313113937272020254"
  27. DATA "34311191737383832204049494718323029474748123237274930174242482123233534301017171"
  28. DATA "2494148432326262534373719114144273730303911121848434346264525273037203416164"
  29. DATA "5472720202436161313154040242"
  30. figuras
  31. inicio
  32. solucion
  33. juego
  34. END
  35.  
  36. SUB dibuja (i, c)
  37. IF c = 0 THEN B$ = "0" ELSE B$ = "15"
  38. pf$ = "bm" + STR$(posx(i) * 75 + 57) + "," + STR$(posy(i) * 75 + 5)
  39. df$ = "s147" + a(t(i)) + "s4bm+1,+1p" + STR$(c) + "," + B$
  40. dn$ = "c" + B$ + "s139bm+" + STR$(dimx(t(i)) + 1) + ",+" + STR$(dimy(t(i)) + 1) + "s4" + num(i)
  41. DRAW "c" + B$ + pf$ + df$ + dn$
  42. END SUB
  43.  
  44. SUB entrada (f, p)
  45. LOCATE 27, 19: PRINT "Mueve la figura          en direccion"
  46. DO
  47. LOCATE 27, 39: PRINT CHR$(219): LOCATE 27, 60: PRINT " ": LOCATE 28, 55: PRINT " "
  48.   DO
  49.   f = INSTR("0123456789", INPUT$(1))
  50.   LOOP WHILE f = 0
  51. LOCATE 27, 38: PRINT f - 1
  52. LOCATE 27, 61: PRINT CHR$(219)
  53.   DO
  54.   p = INSTR("8264", INPUT$(1))
  55.   LOOP WHILE p = 0
  56. LOCATE 27, 61: PRINT " ": LOCATE 27, 60: PRINT CHR$(0) + CHR$(23 + p)
  57. LOCATE 28, 28: PRINT "¿Correcto? (s/n/f) ?  [s]  " + CHR$(219)
  58. SELECT CASE INSTR("nNfF", INPUT$(1))
  59.   CASE 1, 2
  60.   x = 1
  61.   CASE 3, 4
  62.   CLS : END
  63.   CASE ELSE
  64.   x = 0
  65.   p1 = (p = 1): p2 = (p = 2): p3 = (p = 3): p4 = (p = 4): p12 = p1 OR p2: p34 = p3 OR p4
  66.   vi = -dimy(t(f)) * p34 - dimx(t(f)) * p12
  67.   x0 = -(posx(f) + p4 - p3 * (dimx(t(f)) + 1)) * p34 - posx(f) * p12
  68.   y0 = -(posy(f) + p1 - p2 * (dimy(t(f)) + 1)) * p12 - posy(f) * p34
  69.   FOR i = 0 TO vi
  70.   IF tb(x0 - i * p12, y0 - i * p34) = 1 THEN x = 1: BEEP: EXIT FOR
  71.   NEXT i
  72.   END SELECT
  73. LOOP UNTIL x = 0
  74. END SUB
  75.  
  76.  
  77.  
  78.  
  79. SUB figuras
  80. a(2) = "d2r2u2l2"                                      ' Cuadrado pequeño
  81. a(1) = "d4r4u4l4"                                      ' Cuadrado grande
  82. a(3) = "d4r2u4l2 "                                     ' Rectangulo horizontal
  83. a(4) = "d2r4u2l4"                                      ' Rectangulo vertical
  84. FOR i = 0 TO 6: FOR j = 0 TO 5: tb(i, j) = 1: NEXT j, i' Posiciones ocupadas o
  85. tb(4, 2) = 0: tb(4, 3) = 0                             ' libres segun 1/0
  86. FOR i = 1 TO 4: READ dimx(i), dimy(i): NEXT i          ' Campo de comprobacion
  87. FOR i = 1 TO 10: READ t(i), posx(i), posy(i): NEXT i   ' de los movimientos
  88. FOR i = 1 TO 10: READ num(i): NEXT i                   'Número de cada figura
  89. FOR i = 24 TO 27: cs = cs + CHR$(i): NEXT i            'Crea el cursor grafico
  90. FOR i = 0 TO 4: READ sol(i): NEXT i                    'Solucion codificada
  91. mov = 0                                                'Movimientos hasta ahora
  92. END SUB
  93.  
  94. SUB inicio
  95. SCREEN 12
  96. CLS
  97. pantalla
  98. FOR i = 55 TO 202 STEP 4: LINE (358, 358 - i)-(303 + i, 303): NEXT i
  99. FOR i = 203 TO 349 STEP 4: LINE (503, 503 - i)-(156 + i, 156): NEXT i
  100. LOCATE 3, 2: PRINT "Este juego consiste en desplazar el cuadrado grande (3) a la posicion  señalada   ("; CHR$(176); ")  deslizando para ello todos los bloques que sean necesario."
  101. LOCATE 25, 2: PRINT "* Utiliza los cursores y los números asociados a las figuras para ello."
  102. LOCATE 26, 2: PRINT "  -> Si quieres salir , pulsa la opción 'f'."
  103. LOCATE 27, 2: PRINT "  -> Si quieres ver una solución ( en movimiento ) pulsa 'S'."
  104. LOCATE 28, 2: PRINT "Pulsa cualquier tecla para continuar...";
  105. DEF SEG = 0: POKE &H417, PEEK(&H417) OR &H20
  106. END SUB
  107.  
  108. SUB juego
  109. pantalla2
  110. DO
  111. entrada f, p
  112. mueve f, p
  113. LOOP
  114. END SUB
  115.  
  116. SUB mueve (f, p)
  117. p1 = (p = 1): p2 = (p = 2): p3 = (p = 3): p4 = (p = 4): p12 = p1 OR p2: p34 = p3 OR p4
  118. dibuja f, 0
  119. vi = -dimy(t(f)) * p34 - dimx(t(f)) * p12
  120. FOR i = 0 TO vi
  121. x0 = -(posx(f) + p4 - p3 * (dimx(t(f)) + 1)) * p34 - posx(f) * p12
  122. y0 = -(posy(f) + p1 - p2 * (dimy(t(f)) + 1)) * p12 - posy(f) * p34
  123. tb(x0 - i * p12, y0 - i * p34) = 1
  124. x0 = -(posx(f) - p4 * dimx(t(f))) * p34 - posx(f) * p12
  125. y0 = -(posy(f) - p1 * dimy(t(f))) * p12 - posy(f) * p34
  126. tb(x0 - i * p12, y0 - i * p34) = 0
  127. NEXT i
  128. SELECT CASE p
  129.   CASE 1
  130.   posy(f) = posy(f) - 1
  131.   CASE 2
  132.   posy(f) = posy(f) + 1
  133.   CASE 3
  134.   posx(f) = posx(f) + 1
  135.   CASE 4
  136.   posx(f) = posx(f) - 1
  137. END SELECT
  138. dibuja f, f
  139. mov = mov + 1
  140. LOCATE 24, 67: PRINT "Mov.: "; mov; "   "
  141. END SUB
  142.  
  143. SUB pantalla
  144. LOCATE 2, 12: PRINT "-->  J U E G O   D E L   D E S P L A Z A M I E N T O  <--"
  145. FOR i = 1 TO 10: dibuja i, i: NEXT i
  146. END SUB
  147.  
  148. SUB pantalla2
  149. CLS
  150. pantalla
  151. LINE (130, 78)-(507, 380), , B
  152. LINE (0, 0)-(638, 469), , B
  153. END SUB
  154.  
  155. SUB solucion
  156. DO WHILE INSTR("sS", INPUT$(1)) > 0
  157. CLS
  158. pantalla2
  159. LOCATE 4, 18: PRINT "Una posible solución, pero no la más corta ..."
  160. LOCATE 26, 3: PRINT "Pulsa cualquier tecla para continuar...."
  161. FOR j = 0 TO 4
  162. FOR i = 1 TO LEN(sol(j)) / 2
  163. f = VAL(MID$(sol(j), i * 2 - 1, 1))
  164. p = VAL(MID$(sol(j), i * 2, 1))
  165. f = f - 10 * (f = 0)
  166. a$ = INPUT$(1)
  167. mueve f, p
  168. NEXT i, j
  169. LOCATE 27, 3: PRINT "FIN. Pulsa cualquier tecla para continuar....( 'S' para REPETIR )"
  170. RESTORE
  171. figuras
  172. LOOP
  173. END SUB
  174.  
  175.